package com.open.basic.spring;

import org.springframework.boot.system.ApplicationHome;
import org.springframework.boot.system.ApplicationPid;
import org.springframework.boot.system.ApplicationTemp;
import org.springframework.boot.system.JavaVersion;


/**
 * @author: system
 * @Date: 2024/10/19 上午10:50
 * @Version: V1.0
 * @description: |
 */

public class ApplicationPidUtil {

    private static ApplicationPid applicationPid;

    private static ApplicationHome applicationHome;


    private static ApplicationTemp applicationTemp;

    public static String getPid(){
        if (applicationPid == null){
            synchronized (ApplicationPidUtil.class){
                if (applicationPid == null){
                    applicationPid = new ApplicationPid();
                }
            }
        }
        return applicationPid.toString();
    }

    /**
     * 获取项目根目录
     * @return
     */
    public static String getApplicationHome(){
        if (applicationHome == null){
            synchronized (ApplicationPidUtil.class){
                if (applicationHome == null){
                    applicationHome = new ApplicationHome();
                }
            }
        }
        return applicationHome.getDir().getAbsolutePath();
    }


    /**
     * 支持 1.8 - 21
     * @return
     */
    public static String getJavaVersion(){
        return JavaVersion.getJavaVersion().toString();
    }

    /**
     * 获取临时目录
     * @return
     */
    public static String getApplicationTemp(){
        if (applicationTemp == null){
            synchronized (ApplicationPidUtil.class){
                if (applicationTemp == null){
                    applicationTemp = new ApplicationTemp();
                }
            }
        }
        return applicationTemp.getDir().getAbsolutePath();
    }

    /**
     * Instantiator 是一个简单工厂，可以通过注入参数来创建实例
     * @return
     */
    public static void d(){

    }

    public static void main(String[] args) {
        applicationHome = new ApplicationHome();
        System.out.println(applicationHome.getDir().getAbsolutePath());

        System.out.println(getJavaVersion());
        System.out.println(getApplicationTemp());
    }


}
